from fastapi import APIRouter, Depends, Request

from forward.api.h5.schemas.lucky.order import (
    ActivityCreateOrderInSchema,
    ActivityEditOrderInSchema,
    OrderCancleInSchema,
    OrderDetailInSchema,
)
from forward.api.h5.service.lucky.order import OrderService

order = APIRouter(prefix="/order")


@order.post("/create")
async def create(
    request: Request,
    create_order_in: ActivityCreateOrderInSchema,
    order_service: OrderService = Depends(),
):
    user_id = request.state.user_id
    return await order_service.create(create_order_in, user_id)


@order.post("/edit")
async def eidt(
    request: Request,
    edit_in: ActivityEditOrderInSchema,
    order_service: OrderService = Depends(),
):
    user_id = request.state.user_id
    return await order_service.edit(order_id=edit_in.orderId, edit_in=edit_in, user_id=user_id)


@order.post("/list")
async def order_list(
    request: Request,
    order_service: OrderService = Depends(),
):
    user_id = request.state.user_id

    return await order_service.order_list(user_id)


@order.post("/detail")
async def order_detail(
    order_detail_in: OrderDetailInSchema,
    order_service: OrderService = Depends(),
):
    return await order_service.order_detail(order_detail_in.id)


@order.post("/cancel")
async def cancle(
    request: Request,
    cancel_in: OrderCancleInSchema,
    order_service: OrderService = Depends(),
):
    """
    核销码号
    """
    user_id = request.state.user_id
    return await order_service.cancel(
        user_id, cancel_in.activity_id, cancel_in.code, cancel_in.prize_temp_id
    )


@order.post("/test")
async def test(order_service: OrderService = Depends()):

    await order_service.test()

    return {"code": 0, "msg": "ok"}
